package com.ft.turorial.spring.boot.security.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import com.ft.turorial.spring.boot.web.util.SessionUtil;

public class SecurityInterceptor implements HandlerInterceptor {
	
	@Value("${ft.web.static.server}")
	private String staticWebServerHost;
	
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
		SessionUtil.setSession(request);
		
		return true;
	}

	@Override
	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
			ModelAndView modelAndView) throws Exception {
	}

	@Override
	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
			throws Exception {
		SessionUtil.set("staticWebServerHost", staticWebServerHost);
	}

}
